<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>A 页面</title>
</head>
<body>
  <h1>A 页面</h1>
  <button type="button" onclick="openB()">去B</button>
  <script>
    window.name='A'
    function openB(){
      window.open('B.html?code=123','B')
    }
    window.addEventListener('message',receiveMessage,false)
    function receiveMessage(event){
      console.log('收到的消息：',event.data);
    }
  </script>
</body>
</html>